Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

368
Vistas
Is there a way to implement "update service worker on reload"?

I understand that when you reload a tab, the waiting service worker won't be activated, because the previous tab and new tab are overlapped.

But I am wondering if there is a way to implement it by delaying the closing of the old tab or opening of the new tab, such that we can skip waiting and activate the waiting service worker?

I tried this:

    const wb = new Workbox("service-worker.js");
    wb.addEventListener("waiting", () => {
      window.addEventListener('beforeunload', async () => {
        await wb.messageSkipWaiting();
      });
    });

And it does activate the waiting service worker on reload, but the reload sometimes hangs forever, because there is race condition that reloading needs to fetch index.html and assets from the service worker, while the activation of service worker might interrupt the request. For example, if the old SW was handling the request, and suddenly it is replaced by the new SW, the request could hang.

Not sure if there is a better to handle this.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda